<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>水平垂直居中第一种</title>
    <style>
        .parent{
            width: 800px;
            height: 800px;
            position: relative;
            background-color: #eee;
        }
        .child{
            width: 100px;
            height: 100px;
            position:absolute;
            background-color: white;
            left: 50%;
            top:50%;
            transform: translate(-50%,-50%);
        }
    </style>
</head>

<body>   
    <!-- 设置偏移量方式达到水平垂直居中 -->
    <!-- relative不脱离文档流，absolute、fixed脱离文档流 -->
    <div class="parent">
        <div class="child">child</div>
    </div>
</body>

</html>